package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-subarrays-with-majority-element-i/
 * @create 2025/11/9 17:22
 * @since JDK17
 */
class Solution29 {
    public int countMajoritySubarrays(int[] nums, int target) {
        // 主要元素是指出现次数大于其长度一半
        int ans = 0, n = nums.length;
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = i; j < n; j++) {
                cnt += nums[j] == target ? 1 : 0;
                if (cnt > (j - i + 1) / 2) {
                    ans++;
                }
            }
        }

        return ans;
    }
}